package com.aurora.source.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.aurora.source.R;
import com.aurora.source.base.BaseRecyclerAdapter;
import com.aurora.source.base.CommonHolder;
import com.aurora.source.base.PhotoViewActivity;
import com.aurora.source.util.ErrorImgUtil;
import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

/**
 * @author: ww
 * @description:看图片适配器
 * @date: 2018/9/19
 */
public class ImgSeeAdapter extends BaseRecyclerAdapter<String> {

    @Override
    public CommonHolder<String> setViewHolder(ViewGroup parent) {
        return new MyHolder(parent.getContext(), parent, R.layout.item_img);
    }

    public class MyHolder extends CommonHolder<String> {

        @BindView(R.id.iv_img)
        ImageView ivImg;
        @BindView(R.id.iv_delete)
        ImageView ivDelete;
        Context context;
        public MyHolder(Context context, ViewGroup root, int layoutRes) {
            super(context, root, layoutRes);
            this.context = context;
        }

        @Override
        public void bindData(final String s, int positon) {
            ivDelete.setVisibility(View.GONE);
            Glide.with(context)
                    .load(s)
                    .apply(new RequestOptions().placeholder(R.drawable.ic_default).error(ErrorImgUtil.getErrorImgRandom()))
                    .into(ivImg);
            itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent = new Intent(context, PhotoViewActivity.class);
                    List<String> imgFiles = getDataList();
                    ArrayList<String> images = new ArrayList<>(imgFiles);
                    intent.putExtra("title","图片资源预览");
                    intent.putStringArrayListExtra("images",images);
                    intent.putExtra("position",getLayoutPosition());
                    context.startActivity(intent);
                }
            });
        }
    }
}
